package com.focus.xyz.core.pages;

import com.focus.xyz.core.common.keyword.Action;
import org.openqa.selenium.WebDriver;

/**
 * Created by chenmeng on 2016/4/13.
 */
public class BasePage implements IPage {
    private WebDriver driver;
    private Action action;
    protected String url;


    protected BasePage(WebDriver driver,Action action) {
        this.driver = driver;
        this.action = action;
    }

    protected BasePage(WebDriver driver,Action action,String url){
        this.driver = driver;
        this.action = action;
        this.url = url;
    }

    public void switchTo(){
        try{
            action.switchToWindowByUrl(url,true);
        }catch (Exception e){

        }
    }

    public void switchTo(String url){
        try{
            action.pause(3000l);//在切换到新窗口时chrome要等待一段时间，否则切换不成功
            action.switchToWindowByUrl(url,true);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void openPage() throws Exception{
        action.open(url);
        action.waitForPageLoad();
    }

    public void openPage(String url){
        try {
            action.open(url);
            action.waitForPageLoad();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
